package
{
	import de.polygonal.ds.HashMap;
	
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;
	
	public class CSoundManager
	{
		public static const SOUND_1_TITLE		:uint = 1;
		public static const SOUND_2_GAME		:uint = 2;
		public static const SOUND_3_MOVECURSOR	:uint = 3;
		public static const SOUND_4_START		:uint = 4;
		public static const SOUND_5_BYEBYE		:uint = 5;
		public static const SOUND_6_UPGRADE		:uint = 6;
		public static const SOUND_7_EAT			:uint = 7;
		public static const SOUND_8_GETCOIN		:uint = 8;
		public static const SOUND_9_GETGOLD		:uint = 9;
		public static const SOUND_10_SHOWTIME	:uint = 10;
		public static const SOUND_11_15_DAMAGE	:uint = 11;
		public static const SOUND_12_BLOCK		:uint = 12;
		public static const SOUND_13_KNOCK		:uint = 13;
		public static const SOUND_14_GOAL		:uint = 14;
		
		private static var m_instance			:CSoundManager = new CSoundManager;
		private var m_mapSound					:HashMap = new HashMap;
		private var m_mapSoundChannel			:HashMap = new HashMap;
		
//		public static var m_Sound_1_Title			:CSound_1_Title = new CSound_1_Title;
//		private static var m_Channel_1_Title		:SoundChannel = null;
//		
//		public static var m_Sound_2_Game			:CSound_2_Game = new CSound_2_Game;
//		public static var m_Sound_3_MoveCursor		:CSound_3_MoveCursor = new CSound_3_MoveCursor;
//		public static var m_Sound_4_Start			:CSound_4_Start = new CSound_4_Start;
//		public static var m_Sound_5_ByeBye			:CSound_5_ByeBye = new CSound_5_ByeBye;
//		public static var m_Sound_6_Upgrade			:CSound_6_Upgrade = new CSound_6_Upgrade;
//		public static var m_Sound_7_Eat				:CSound_7_Eat = new CSound_7_Eat;
//		public static var m_Sound_8_GetCoin			:CSound_8_GetCoin = new CSound_8_GetCoin;
//		public static var m_Sound_9_GetGold			:CSound_9_GetGold = new CSound_9_GetGold;
//		public static var m_Sound_10_ShowTime		:CSound_10_ShowTime = new CSound_10_ShowTime;
//		public static var m_Sound_11_15_Damage		:CSound_11_15_Damage = new CSound_11_15_Damage;
//		public static var m_Sound_12_Block			:CSound_12_Block = new CSound_12_Block;
//		public static var m_Sound_13_Knock			:CSound_13_Knock = new CSound_13_Knock;
//		public static var m_Sound_14_Goal			:CSound_14_Goal = new CSound_14_Goal;
		
		public static function get instance() :CSoundManager { return m_instance; }
		
		public function CSoundManager()
		{
			m_mapSound.insert(SOUND_1_TITLE,		new CSound_1_Title());
			m_mapSound.insert(SOUND_2_GAME,			new CSound_2_Game());
			m_mapSound.insert(SOUND_3_MOVECURSOR,	new CSound_3_MoveCursor());
			m_mapSound.insert(SOUND_4_START,		new CSound_4_Start());
			m_mapSound.insert(SOUND_5_BYEBYE,		new CSound_5_ByeBye());
			m_mapSound.insert(SOUND_6_UPGRADE,		new CSound_6_Upgrade());
			m_mapSound.insert(SOUND_7_EAT,			new CSound_7_Eat());
			m_mapSound.insert(SOUND_8_GETCOIN,		new CSound_8_GetCoin());
			m_mapSound.insert(SOUND_9_GETGOLD,		new CSound_9_GetGold());
			m_mapSound.insert(SOUND_10_SHOWTIME,	new CSound_10_ShowTime());
			m_mapSound.insert(SOUND_11_15_DAMAGE,	new CSound_11_15_Damage());
			m_mapSound.insert(SOUND_12_BLOCK,		new CSound_12_Block());
			m_mapSound.insert(SOUND_13_KNOCK,		new CSound_13_Knock());
			m_mapSound.insert(SOUND_14_GOAL,		new CSound_14_Goal());
		}
		public function PlaySound(nSound :uint, nLoop :int = 0) :void
		{
			var cSound :Sound = m_mapSound.find(nSound)
			if (cSound == null) return;
			
			m_mapSoundChannel.insert(nSound, cSound.play(0, nLoop));
		}
		public function StopSound(nSound :uint) :void
		{
			var refSoundChannel :SoundChannel = m_mapSoundChannel.find(nSound)
			if (refSoundChannel == null) return;
			
			refSoundChannel.stop();
			m_mapSoundChannel.remove(nSound);
		}
		public function SetAllVolume(nValue :Number) :void
		{
			var refTransform :SoundTransform = null;
			var refSoundChannel :SoundChannel = null;
			
			refSoundChannel = m_mapSoundChannel.find(SOUND_1_TITLE)
			if (refSoundChannel != null)
			{
				refTransform = refSoundChannel.soundTransform;
				refTransform.volume = nValue;
				refSoundChannel.soundTransform = refTransform;
			}
			
			refSoundChannel = m_mapSoundChannel.find(SOUND_2_GAME)
			if (refSoundChannel != null)
			{
				refTransform = refSoundChannel.soundTransform;
				refTransform.volume = nValue;
				refSoundChannel.soundTransform = refTransform;
			}
		}
		
	}
}